package com.ruoyi.system.controller;

import java.util.*;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.TaskLogThree;
import com.ruoyi.system.domain.TaskLogTwo;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TaskThree;
import com.ruoyi.system.service.ITaskThreeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2024-09-18
 */
@RestController
@RequestMapping("/system/three")
public class TaskThreeController extends BaseController
{
    @Autowired
    private ITaskThreeService taskThreeService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:three:list')")
    @GetMapping("/list")
    public TableDataInfo list(TaskThree taskThree)
    {
        startPage();
        List<TaskThree> list = taskThreeService.selectTaskThreeList(taskThree);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:three:export')")
//    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskThree taskThree)
    {
        List<TaskThree> list = taskThreeService.selectTaskThreeList(taskThree);
        ExcelUtil<TaskThree> util = new ExcelUtil<TaskThree>(TaskThree.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:three:query')")
    @Log(title = "三号表详情", businessType = BusinessType.DETAIL , tableIndex = 3)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(taskThreeService.selectTaskThreeById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:three:add')")
    @Log(title = "三号表新增", businessType = BusinessType.INSERT , tableIndex = 3 , isAnalysisJson = true)
    @PostMapping
    public AjaxResult add(@RequestBody TaskThree taskThree)
    {

        taskThreeService.insertTaskThree(taskThree);

        TaskLogThree taskLogThree = new TaskLogThree();
        taskLogThree.setTaskId(taskThree.getId());
        return AjaxResult.success("200",taskLogThree);
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:three:edit')")
    @Log(title = "三号表修改", businessType = BusinessType.UPDATE , tableIndex = 3 )
    @PutMapping
    public AjaxResult edit(@RequestBody TaskThree taskThree)
    {

        taskThreeService.updateTaskThree(taskThree);
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("id", taskThree.getId());

        return AjaxResult.success("操作成功",map);
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:three:remove')")
    @Log(title = "三号表删除", businessType = BusinessType.DELETE , tableIndex = 3 )
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {

        taskThreeService.deleteTaskThreeByIds(ids);
        String id = Arrays.toString(ids).replace("[", "").replace("]", "");
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("id", id);
        return AjaxResult.success("操作成功",map);
    }


    /**
     * excel模板导出
     */
    @PreAuthorize("@ss.hasPermi('system:three:export')")
    @Log(title = "账号密码导出模板", businessType = BusinessType.EXPORT)
    @PostMapping("/templateExport")
    public void export(HttpServletResponse response)
    {
        TaskThree taskThree = new TaskThree();
        taskThree.setTaskId(1L);
        taskThree.setCodeName("模板");
//        taskThree.setCreateName("模板");
        taskThree.setHostName("模板");
        taskThree.setType("模板");
        taskThree.setAddress("模板");
        taskThree.setAccount("模板");
        taskThree.setPassword("模板");
        taskThree.setBindInfo("模板");

        List<TaskThree> taskThreeList = new ArrayList<>();
        taskThreeList.add(taskThree);
        ExcelUtil<TaskThree> util = new ExcelUtil<TaskThree>(TaskThree.class);
        util.exportExcel(response, taskThreeList, "账号密码导出模板");
    }


    /**
     * excel数据导入
     */
    @Log(title = "账号密码数据导入", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<TaskThree> util = new ExcelUtil<TaskThree>(TaskThree.class);
        List<TaskThree> taskList = util.importExcel(file.getInputStream());

        String resultString = taskThreeService.importUser(taskList);
        return AjaxResult.success(resultString);
    }














}
